package in.cent.client.main;

import in.cent.client.communication.CommunicationHandler;
import in.cent.client.gui.Display;

import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JApplet;
import javax.swing.JComponent;
import javax.swing.JPanel;

public class MainApplet extends JApplet
{
	private static final long serialVersionUID = 1L;

	private JComponent panel;
	private Display display = null;

	public MainApplet()
	{
		new CommunicationHandler("127.0.0.1");
		panel = new JComponent()
		{
			private static final long serialVersionUID = 1L;

			@Override
			public void paintComponent(Graphics g)
			{
				if (MainApplet.this.display == null)
				{
					g.drawString("No Display", 0, 16);
					return;
				}
				MainApplet.this.display.draw((Graphics2D) g);
			}
		};

		this.add(panel);
	}

	public void setDisplay(Display d)
	{
		display = d;
		if (d != null)
			d.registerApplet(this);
	}

	public void init()
	{
	}
}
